package com.hqq.behaviour.specification.app;

import com.hqq.behaviour.specification.creature.*;
import com.hqq.behaviour.specification.property.Color;
import com.hqq.behaviour.specification.property.Movement;
import com.hqq.behaviour.specification.property.Size;
import com.hqq.behaviour.specification.selector.ColorSelector;
import com.hqq.behaviour.specification.selector.MovementSelector;
import com.hqq.behaviour.specification.selector.SizeSelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * App
 * Created by heqianqian on 2017/6/20.
 */
public class App {

    private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) {
        List<Creature> creatures =
                Arrays.asList(new Goblin(), new Octopus(), new Dragon(), new Shark(), new Troll(),
                        new KillerBee());
        LOGGER.info("Find all walking creatures");
        List<Creature> walkingCreatures =
                creatures.stream().filter(new MovementSelector(Movement.WALKING))
                        .collect(Collectors.toList());
        walkingCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
        LOGGER.info("Find all dark creatures");
        List<Creature> darkCreatures =
                creatures.stream().filter(new ColorSelector(Color.DARK))
                        .collect(Collectors.toList());
        darkCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
        LOGGER.info("Find all large creatures");
        List<Creature> largeCreatures =
                creatures.stream().filter(new SizeSelector(Size.LARGE))
                        .collect(Collectors.toList());
        largeCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
        LOGGER.info("Find all red and flying creatures");
        List<Creature> redAndFlyingCreatures =
                creatures.stream()
                        .filter(new ColorSelector(Color.RED).and(new MovementSelector(Movement.FLYING)))
                        .collect(Collectors.toList());
        redAndFlyingCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
    }
}
